/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.test;

import java.io.File;
  import java.io.IOException;
  import org.tmatesoft.svn.core.SVNCommitInfo;
  import org.tmatesoft.svn.core.SVNDepth;
  import org.tmatesoft.svn.core.SVNException;
  import org.tmatesoft.svn.core.SVNPropertyValue;
  import org.tmatesoft.svn.core.SVNURL;
  import org.tmatesoft.svn.core.wc.SVNClientManager;
  import org.tmatesoft.svn.core.wc.SVNDiffClient;
  import org.tmatesoft.svn.core.wc.SVNRevision;
  import org.tmatesoft.svn.core.wc.SVNWCClient;
  /**
   * This examples demonstrate how you can run WORKING:HEAD diff.
   *
   * @version 1.2.0
   * @author  TMate Software Ltd.
   */
  public class DiffWCToRepository {

       public static void main (String[] args) {
           //initialize SVNKit to work through file:/// protocol
           SamplesUtility.initializeFSFSprotocol();
   
           File baseDirectory = new File("");
           File reposRoot = new File(baseDirectory, "exampleRepository");
          File wcRoot = new File(baseDirectory, "exampleWC");
   
           try {
               //1. first create a repository and fill it with data
               SamplesUtility.createRepository(reposRoot);
               //2. populate the repository with the greek tree in a single transaction
               SVNCommitInfo info = SamplesUtility.createRepositoryTree(reposRoot);
               //pring out the commit information
               System.out.println(info);
   
               //3. checkout the entire repository tree
               SVNURL reposURL = SVNURL.fromFile(reposRoot);
               SamplesUtility.checkOutWorkingCopy(reposURL, wcRoot);
   
               //4. now make some changes to the working copy
               SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text appended to 'iota'", true);
               SamplesUtility.writeToFile(new File(wcRoot, "A/mu"), "New text in 'mu'", false);
   
               SVNClientManager clientManager = SVNClientManager.newInstance();
               SVNWCClient wcClient = SVNClientManager.newInstance().getWCClient();
               //set some property on a working copy directory
               wcClient.doSetProperty(new File(wcRoot, "A/B"), "spam", SVNPropertyValue.create("egg"), false,
                       SVNDepth.EMPTY, null, null);
   
               //5. now run diff the working copy against the repository
               SVNDiffClient diffClient = clientManager.getDiffClient();
               /*
                * This corresponds to 'svn diff -rHEAD'.
                */
               diffClient.doDiff(wcRoot, SVNRevision.UNDEFINED, SVNRevision.WORKING, SVNRevision.HEAD,
                       SVNDepth.INFINITY, true, System.out, null);
           } catch (SVNException svne) {
               System.out.println(svne.getErrorMessage());
               System.exit(1);
           } catch (IOException ioe) {
               ioe.printStackTrace();
               System.exit(1);
           }
       }
   
   }